#!/usr/bin/perl -w
#
# whether large_page or memlock is enable
# @param $1 install home
# @param $2 pattern
# @param $3 delimiter
# @param $4 host
# @param $5 port
# @param $6 username
# @param $7 password
# -- Created 2009.07.06 by DavidLi -initial
use strict;
my $SQL="show global variables like 'locked_in_memory';show global variables like 'large_pages'";
my ($MYSQL_HOME,$RE,$DELIM,$HOST,$PORT,$USER,$PASS) = @ARGV;
my $PARAM="";
$PARAM="$PARAM -h\"$HOST\"" if (defined($HOST) && $HOST ne "");
$PARAM="$PARAM -P\"$PORT\"" if (defined($PORT) && $PORT ne "");
$PARAM="$PARAM -u\"$USER\"" if (defined($USER) && $USER ne "");
$PARAM="$PARAM -p\"$PASS\"" if (defined($PASS) && $PASS ne "");
my $MYSQL= defined ($MYSQL_HOME) ? "$MYSQL_HOME/bin/mysql" : "/usr/local/mysql/bin/mysql";
#my $MYSQL="$MYSQL_HOME/bin/mysql";
my $MYSQLADMIN= defined $MYSQL_HOME ? "$MYSQL_HOME/bin/mysqladmin" : "mysqladmin";
#my $MYSQLADMIN="$MYSQL_HOME/bin/mysqladmin"; 
if ($^O =~ m/MSWin32/) {
  $MYSQL =~ s/\//\\/g;
  $MYSQLADMIN =~ s/\//\\/g;
}
# Check if mysqld is alive
#my $retmsg=`$MYSQLADMIN $PARAM ping 2>&1`;
#chomp($retmsg);
#if ( "$retmsg" ne "mysqld is alive" ) {
#    print "em_error=Status${DELIM}Down\n";
#    exit 1;
#}


# If path to mysqladmin is defined - use it. Otherwise, assume it's in default PATH.
#my $mysql_bin = defined $mysql_path ? "$mysql_path/mysql" : "mysql";

#my $conn_args="--protocol=tcp --host='$host'" .
#       (defined $port     ? " --port='$port'"         : '') .
#       (defined $user     ? " --user='$user'"         : '') .
#       (defined $password ? " --password='$password'" : '') ;

#my @lines=`$mysql_bin $conn_args --batch --skip-column-names <<!
#show full processlist;
#!`;

my @lines=`$MYSQL -N -s $PARAM --batch  -e"$SQL"`;
#chomp(@lines);
if ( @lines eq 1 ) {

foreach my $line (@lines) {
  my $str="";
  chomp $line;
  my @row = split(/\t/,$line);
  # variable_name|value
  print "em_result=$row[0]|$row[1]\n";
}
  print "em_result=large_pages|NOSUPPORT\n";
}else {

foreach my $line (@lines) {
  my $str="";
  chomp $line;
  my @row = split(/\t/,$line);
  # variable_name|value
  print "em_result=$row[0]|$row[1]\n";
 }
} 

